import cron from "node-cron";
import schedule from "node-schedule";
import { sendGroupCard } from "./groupBot.js";

import { updateZhuBoTable } from "./updateZhuBoTable.js";
import {dingtalkBotConfig} from "../config/dingtalkBot.js";

console.log("✅ 启动钉钉群定时推送任务...");

// 9点、10点、11点和19点执行任务
schedule.scheduleJob('0 9 * * *', async function () {
    console.log(`⏰ 执行钉钉群推送任务... ${new Date().toLocaleString()}`);
    await sendGroupCard(dingtalkBotConfig.secret, dingtalkBotConfig.webhook);
    await sendGroupCard(dingtalkBotConfig.secret_1, dingtalkBotConfig.webhook_1);
    await sendGroupCard(dingtalkBotConfig.secret_2, dingtalkBotConfig.webhook_2);
});

schedule.scheduleJob('0 10 * * *',async function () {
    console.log(`⏰ 执行钉钉群推送任务... ${new Date().toLocaleString()}`);
    await sendGroupCard(dingtalkBotConfig.secret, dingtalkBotConfig.webhook);
    await sendGroupCard(dingtalkBotConfig.secret_1, dingtalkBotConfig.webhook_1);
    await sendGroupCard(dingtalkBotConfig.secret_2, dingtalkBotConfig.webhook_2);
});

schedule.scheduleJob('0 11 * * *',async function () {
    console.log(`⏰ 执行钉钉群推送任务... ${new Date().toLocaleString()}`);
    await sendGroupCard(dingtalkBotConfig.secret, dingtalkBotConfig.webhook);
    await sendGroupCard(dingtalkBotConfig.secret_1, dingtalkBotConfig.webhook_1);
    await sendGroupCard(dingtalkBotConfig.secret_2, dingtalkBotConfig.webhook_2);
});

schedule.scheduleJob('0 19 * * *',async function () {
    console.log(`⏰ 执行钉钉群推送任务... ${new Date().toLocaleString()}`);
    await sendGroupCard(dingtalkBotConfig.secret, dingtalkBotConfig.webhook);
    await sendGroupCard(dingtalkBotConfig.secret_1, dingtalkBotConfig.webhook_1);
    await sendGroupCard(dingtalkBotConfig.secret_2, dingtalkBotConfig.webhook_2);
});


// 每小时整点执行更新
schedule.scheduleJob('55 * * * *',  async function() {
    console.log("🚀 每小时整点执行数据更新：", new Date().toLocaleString());
    await updateZhuBoTable();
});

// // 手动测试用（需要可取消注释）
// sendGroupCard();
